package com.woniu.airent.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.woniu.airent.dto.SearchHouseDto;
import com.woniu.airent.mapper.SearchHouseMapper;
import com.woniu.airent.service.SearchHouseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Comparator;
import java.util.List;

/**
 * description:
 *
 * @author AlenHx
 * @create 2020/10/12
 * @since 1.0.0
 */

@Service
public class SearchHouseServiceImpl implements SearchHouseService {

    @Autowired
    SearchHouseMapper searchHouseMapper;



/*    public PageInfo<SearchHouseDto> findHouse(SearchHouseDto searchHouseDto,int pageNum,int pageSize){
        PageHelper.startPage(pageNum,pageSize);*/

    public PageInfo<SearchHouseDto> findHouse(SearchHouseDto searchHouseDto,int pageNum,int pageSize,int priceState,int areaState){
        PageHelper.startPage(pageNum,pageSize);
        List<SearchHouseDto> houseList = searchHouseMapper.selectHouse(searchHouseDto);
        if (priceState==1){
            houseList.sort(new Comparator<SearchHouseDto>() {
                @Override
                public int compare(SearchHouseDto o1, SearchHouseDto o2) {
                    return o1.getRentPrice() - o2.getRentPrice();
                }
            });
        }else if(priceState==0){
            houseList.sort(new Comparator<SearchHouseDto>() {
                @Override
                public int compare(SearchHouseDto o1, SearchHouseDto o2) {
                    return o2.getRentPrice() - o1.getRentPrice();
                }
            });
        }
        return new PageInfo<>(houseList);
    }





}
